package com.aboo.trade.action;

import com.aboo.frame.constant.FlagEnum;
import com.aboo.frame.vo.ReturnVO;
import com.aboo.trade.domain.PlatformPO;
import com.aboo.trade.facade.PlatformFacade;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@RestController
@RequestMapping("/trade")
public class PlatformAction {

    @Resource
    private PlatformFacade platformFacade;

    @RequestMapping("/savePlatform")
    public ReturnVO<PlatformPO> savePlatform() {
        ReturnVO<PlatformPO> rv = new ReturnVO<>();

        LocalDateTime ldt = LocalDateTime.now();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dateStr = dtf.format(ldt);

        PlatformPO platform = new PlatformPO();
        platform.setPlatformCode("Platform" + dateStr);
        platform.setPlatformName("测试版");
        platform.setRemark("测试版备注");
        platform.setEctFlag(FlagEnum.SUCCESS.getValue());
        platformFacade.savePlatform(platform);
        rv.setData(platform);

        log.info(JSONObject.toJSONString(platform));
        return rv;
    }

}
